package com.brand.prisd.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.brand.prisd.R;
import com.brand.prisd.ViewHolder.Type1ViewHolder;
import com.brand.prisd.ViewHolder.Type2ViewHolder;
import com.brand.prisd.ViewHolder.Type3ViewHolder;
import com.brand.prisd.bean.VariableStorage;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;


/**
 * A simple {@link Fragment} subclass.
 * 我 这个页面
 */
public class MeFragment extends Fragment {


    @BindView(R.id.rv)
    RecyclerView rv;
    Unbinder unbinder;

    public MeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_me, container, false);
        unbinder = ButterKnife.bind(this, view);
        initView();
        return view;
    }

    private void initView() {
        rv.setLayoutManager(new LinearLayoutManager(getContext()));
        rv.setAdapter(new RVAdapter());
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    class RVAdapter extends RecyclerView.Adapter {

        @Override
        public int getItemViewType(int position) {
            switch (position) {
                case 0:
                case 2:
                case 5:
                case 8:
                case 11:
                case 13:
                    return VariableStorage.ITEM_VIEW_TYPE_1;
                case 1:
                    return VariableStorage.ITEM_VIEW_TYPE_2;
                case 3:
                case 4:
                case 6:
                case 7:
                case 9:
                case 10:
                case 12:
                    return VariableStorage.ITEM_VIEW_TYPE_3;
            }
            return 0;

        }

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
            switch (viewType) {
                case VariableStorage.ITEM_VIEW_TYPE_1:
                    return new Type1ViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.layout_divide, viewGroup, false));
                case VariableStorage.ITEM_VIEW_TYPE_2:
                    return new Type2ViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.me_type2_item, viewGroup, false));
                case VariableStorage.ITEM_VIEW_TYPE_3:
                    return new Type3ViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.me_type3_item, viewGroup, false));
            }
            return null;
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
            if (viewHolder instanceof Type3ViewHolder) {
                Type3ViewHolder type3ViewHolder = (Type3ViewHolder) viewHolder;
                type3ViewHolder.setData(position);
            }
        }


    @Override
    public int getItemCount() {
        return VariableStorage.MeFragment_RV_ItemCounts;
    }

    @OnClick(R.id.cl_container)
    public void onViewClicked() {
    }
}
}
